package com.yang.service.impl;

import com.aliyun.openservices.ons.api.Action;
import com.aliyun.openservices.ons.api.ConsumeContext;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.MessageListener;
import com.aliyun.openservices.shade.com.alibaba.fastjson.JSON;
import com.yang.entity.SatelliteRemoteSensingFireData;
import lombok.extern.slf4j.Slf4j;

/**
 * 山火Topic消息监听器
 */
@Slf4j
public class FireTopicMessageListener implements MessageListener {

    @Override
    public Action consume(Message message, ConsumeContext consumeContext) {
        log.info("Receive message:{}", new String(message.getBody()));
        String receiveMessage = new String(message.getBody());
        SatelliteRemoteSensingFireData satelliteRemoteSensingFireData = JSON.parseObject(receiveMessage, SatelliteRemoteSensingFireData.class);
        log.info("转换为对象后：{}", JSON.toJSONString(satelliteRemoteSensingFireData));
        // 返回Action.CommitMessage表示消费成功，消息会被删除
        // 返回Action.ReconsumeLater表示消费失败，消息稍后会被重新投递
        return Action.CommitMessage;
    }
}
